package com.ticket.sass.admin.controller;

/**
 * @author ywb
 * @date 2024-07-19 11:50
 */

import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.ticket.sass.admin.business.DouyinLocalLifeConfigBusiness;
import com.ticket.sass.admin.dto.input.douyin.DouyinLocalLifeConfigInput;
import com.ticket.sass.admin.dto.output.douyin.DouyinLocalLifeConfigOutput;
import com.ticket.sass.admin.model.ResultModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Optional;

@RestController
@RequestMapping("/douyin/config")
@Api(tags = "抖音配置")
@ApiSupport(order = 8)
public class DouyinLocalLifeConfigController {
    
    @Autowired
    private DouyinLocalLifeConfigBusiness configBusiness;
    
    @PutMapping
    @ApiOperation("新增或修改配置")
    public ResultModel<String> saveOrUpdateConfig(@RequestBody @Valid DouyinLocalLifeConfigInput input) {
        configBusiness.saveOrUpdateConfig(input);
        return ResultModel.success();
    }
    
    @GetMapping
    @ApiOperation("获取配置")
    public ResultModel<DouyinLocalLifeConfigOutput> getConfigById() {
        Optional<DouyinLocalLifeConfigOutput> output = configBusiness.getConfigById();
        return output.map(ResultModel::success)
            .orElseGet(() -> ResultModel.success(null));
    }
}

